home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / progressbars / initialize.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.3 KB  |  166 lines

  1. /*
  2.     File:        Initialize.c
  3.  
  4.     Contains:    Initialization code for this application
  5.  
  6.     Written by: Chris White    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/10/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24.  
  25. #pragma segment Initialize
  26.  
  27.  
  28.  
  29. // System includes
  30. #include <Resources.h>
  31. #include <Processes.h>
  32.  
  33. #ifndef __QUICKDRAW__
  34.     #include <Quickdraw.h>
  35. #endif
  36.  
  37. #ifndef __FONTS__
  38.     #include <Fonts.h>
  39. #endif
  40.  
  41. #ifndef __TEXTEDIT__
  42.     #include <TextEdit.h>
  43. #endif
  44.  
  45. #ifndef __DIALOGS__
  46.     #include <Dialogs.h>
  47. #endif
  48.  
  49. #ifndef __GESTALT__
  50.     #include <Gestalt.h>
  51. #endif
  52.  
  53. #ifndef __SEGLOAD__
  54.     #include <SegLoad.h>
  55. #endif
  56.  
  57. #ifndef __CODEFRAGMENTS__
  58.     #include <CodeFragments.h>
  59. #endif
  60.  
  61. #ifndef __THREADS__
  62.     #include <Threads.h>
  63. #endif
  64.  
  65.  
  66.  
  67.  
  68. // Application includes
  69.  
  70. #ifndef __BAREBONES__
  71.     #include "BareBones.h"
  72. #endif
  73.  
  74. #ifndef __PROTOTYPES__
  75.     #include "Prototypes.h"
  76. #endif
  77.  
  78.  
  79.  
  80. // static prototypes
  81. static Boolean CheckConfiguration ( void );
  82.  
  83.  
  84.  
  85.  
  86. void InitToolbox ( void )
  87. {    
  88.     
  89.     InitGraf ( &qd.thePort );
  90.     InitFonts ( );
  91.     InitWindows ( );
  92.     InitMenus ( );
  93.     TEInit ( );
  94.     InitDialogs ( nil );
  95.     InitCursor ( );
  96.     
  97.     FlushEvents ( everyEvent, 0 );
  98.     
  99.     return;
  100. }
  101.  
  102.  
  103.  
  104. void InitApplication ( void )
  105. {
  106.     SetMenuBar ( GetNewMBar ( kMenuBarID ) );
  107.     AppendResMenu ( GetMenuHandle ( kAppleMenu ), 'DRVR' );
  108.     DrawMenuBar ( );
  109.     
  110.     if ( !CheckConfiguration ( ) )
  111.     {
  112.         AlertUser ( kNeedSystem7, 0, nil );
  113.         ExitToShell ( );
  114.     }
  115.     
  116.     gQuit = false;                          // Initialize flag that controls main event loop
  117.     gSleepTime = kSleepTime;
  118.     
  119.     InstallAppleEventHandlers ( );
  120.     
  121.     AdjustMenus ( );
  122.     
  123.     // Create any RoutineDescriptors we may need
  124.     gOutlineUserItemUPP = NewUserItemProc ( OutlineUserItem );
  125.     
  126.     return;
  127. }
  128.  
  129.  
  130.  
  131. //
  132. // Verify that we can run on the current configuration
  133. //
  134. static Boolean CheckConfiguration ( void )
  135. {
  136.     SInt32        theResult;
  137.     OSErr        theErr;
  138.     Boolean        bHasAppleEvents;
  139.     
  140.     
  141.     
  142.     // We require AppleEvent Manager
  143.     theErr = Gestalt ( gestaltAppleEventsAttr, &theResult );
  144.     bHasAppleEvents = (theErr == noErr && (theResult & (1L << gestaltAppleEventsPresent)));
  145.     
  146.     // We would like the Thread Manager
  147.     theErr = Gestalt ( gestaltThreadMgrAttr, &theResult );
  148.     gHasThreadManager = (theErr == noErr && (theResult & (1L << gestaltThreadMgrPresent)));
  149.     
  150.     // It isn't enough to use Gestalt because we may not have successfully linked
  151.     // to the shared library. So, we also need to test one of the symbols from the
  152.     // library against kUnresolvedSymbol to make sure we have a valid connection
  153.     // to it. Things like memory limitations or someone having a library open with
  154.     // write permission could cause it to fail.
  155.     
  156. #if GENERATINGCFM
  157.     if ( gHasThreadManager )
  158.         gHasThreadManager = (NewThread != (void*) kUnresolvedCFragSymbolAddress);
  159. #endif
  160.     
  161.     
  162.     return bHasAppleEvents;
  163. }
  164.  
  165.  
  166.